<template>
	<view>
		<u-navbar title="购保记录" placeholder autoBack bgColor="#c1282d" leftIconColor="#ffffff">
			<view class="flexright xiaobai" slot="right" @click="yhdhshow = true">切换企业</view>
		</u-navbar>
		<u-sticky>
			<view class="ffffff">
				<u-tabs :list="list1" :scrollable="false" lineColor="#c1282e" @click="changetab" :activeStyle="{
					    color: '#000000',
					    fontWeight: 'bold',
					    transform: 'scale(1.05)'
					}" :inactiveStyle="{
					            color: '#666666',
								fontWeight: '500',
					            transform: 'scale(1)'
					        }" itemStyle="height: 44px;"></u-tabs>
			</view>
		</u-sticky>
		<view class="mainpadding">
			<view class="flexbetween ssbox" style="background-color: #fff;">
				<view class="flexleft">
					<u-icon name="search" color="#999" size="20"></u-icon>
					<input type="text" placeholder="请输入搜索内容" class="hei_text main_size bold" v-model="keywords"
						confirm-type="search" @confirm="init()">
				</view>
				<view class="rightss" @click="init()">搜索</view>
			</view>
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id" @click="jumpdetail(item)">
				<view class="flexbetween">
					<!-- 状态:0=待参保,4已申报,1=在保,3=待退保,2=停保,， -->
					<view class="flexleft">
						<view class="xiaohei main_size">参保人：{{item.name}}</view>
						<u-icon name="arrow-right-double" v-show="item.is_self==1" color="#c1282e" size="20"></u-icon>
					</view>
					<view class="lable" v-if="item.status==2 && item.is_today==1">今日停保</view>
					<view class="lable" v-if="item.status==0">待参保</view>
					<view class="lable" v-if="item.status==4">已申报</view>
					<view class="lable" v-if="item.status==5">工伤</view>
					<view class="lable" v-if="item.status==6">已理赔</view>
					<view class="lable" v-if="item.status==2 && item.is_today!=1">已停保</view>
					<view class="lable" v-if="item.status==1 && item.is_today==1"
						style="background-color: #c1282e;color: #fff;">明日生效</view>
						<view class="lable" v-if="item.status==1 && item.is_today!=1">在保</view>
					<view class="lable" v-if="item.status==3">待退保</view>
				</view>
				<!-- <view class="xiaohei margin_top2 main_size" v-if="item.user_gb_xz_id==5">性别：{{item.sex==1?"男":"女"}}
				</view> -->
				<!-- <view class="xiaohei margin_top2 main_size" v-if="item.user_gb_xz_id==5">手机号：{{item.tel}}</view> -->
				<view class="xiaohei margin_top2 ">身份证号：{{item.idcard}}</view>
				<!-- <view class="xiaohei margin_top2 main_size" v-if="item.user_gb_xz_id==5">身份证居住地：{{item.address}}</view> -->
				<view class="flexbetween">
					<view class="xiaohei margin_top2 " v-if="item.user_gb_xz_id==5">岗位：{{item.gangwei.name}}</view>
					<view class="xiaohei margin_top2 ">购买时间：{{item.buytime_text}}</view>
				</view>
				
				<!-- <view class="xiaohei margin_top2 main_size" v-if="item.user_gb_xz_id==5">合同公司：{{item.htcompany.name}}
				</view> -->
				<view class="flexbetween">
					<view class="xiaohei margin_top2 ">公司：{{item.company.name}}</view>
					
				</view>
				<!-- <view class="xiaohei margin_top2 main_size" v-if="item.user_gb_xz_id!=5">险种：{{item.xz_name}}</view>
				<view class="xiaohong margin_top2 main_size" v-if="item.user_gb_xz_id==5">险种：{{item.xz_name}}</view> -->
				
				<!-- 状态:0=待参保,1=在保,2=停保,3=待退保 -->
				<view class="flexright margin_top">
					<view class="submitbtn margin_left2" v-if="item.status==2" style="width: 150rpx;"
						@click.stop="xubaostart(item.id)">续保</view>
					<view class="submitbtn margin_left2"
						v-if="item.status==1 && item.user_gb_xz_id!=5 && item.status!=4"
						style="width: 150rpx;background-color: #f8f8f8;color: #c1282e;" @click.stop="tingbaostart(item.id)">
						停保</view>
					<view class="submitbtn margin_left2" v-if="item.status==0 || item.status==2"
						style="width: 150rpx;background-color: #f8f8f8;color: #c1282e;" @click.stop="trashfnstart(item.id)">
						删除</view>
					<view class="submitbtn margin_left2"
						v-if="item.status==1 && item.user_gb_xz_id==5 && item.is_today!=1 && item.is_self==1"
						style="width: 150rpx;background-color: #f8f8f8;color: #c1282e;" @click.stop="tuibaostart(item.id)">退保
					</view>
				</view>
				<view class="flexright">
				</view>
			</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
		<u-picker :show="yhdhshow" :columns="yhdhcolumns" title="" @cancel="yhdhshow=false" @confirm="yhdhconfirm"
			keyName="name"></u-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				yhdhcolumns: [],
				yhdhshow: false,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				tabsid: 0,
				list1: [{
						name: '全部',
						value: 0,
					}, {
						name: '在保',
						value: 1,
					},
					{
						name: '停保',
						value: 2,
					}
				],
				modal: {
					modalShow: false,
					title: "是否确认停保？",
				},
				currentid: "",
				keywords: "",
				company_name:"",
				company_id:"",
			}
		},
		onLoad() {
			this.init()
			this.getyhdh()
		},
		methods: {
			jumpdetail(item){
				if(item.is_self!=1) return 
				uni.navigateTo({
					url:"/pages/tab4/goubaojlxq?id="+item.id
				})
			},
			yhdhconfirm(e) {
				this.company_name = e.value[0].name
				this.company_id = e.value[0].id
				this.yhdhshow = false
				this.init()
			},
			getyhdh() {
				httpRequest.request('/api/user/companyIndex', 'GET', {}).then(res => {
					this.yhdhcolumns.push(res.data)
				})
			},
			tingbaostart(id) {
				this.currentid = id
				this.modal.title = "是否确认停保？"
				this.modal.modalShow = true
			},
			xubaostart(id) {
				this.currentid = id
				this.modal.title = "是否确认续保？"
				this.modal.modalShow = true
			},
			tuibaostart(id) {
				this.currentid = id
				this.modal.title = "是否确认退保？"
				this.modal.modalShow = true
			},
			trashfnstart(id) {
				this.currentid = id
				this.modal.title = "是否确认删除？"
				this.modal.modalShow = true
			},
			modalSure() {
				if (this.modal.title == "是否确认停保？") {
					this.tingbaoFn()
				} else if (this.modal.title == "是否确认续保？") {
					this.xubaoFn()
				} else if (this.modal.title == "是否确认退保？") {
					this.tuibaoFn()
				} else if (this.modal.title == "是否确认删除？") {
					this.shanchuFn()
				}
				this.modalcancel()
			},
			tuibaoFn() {
				httpRequest.request('/api/user/exitUserGb', 'GET', {
					id: this.currentid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.init()
					}
				})
			},
			shanchuFn() {
				httpRequest.request('/api/user/delUserGb', 'GET', {
					id: this.currentid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.init()
					}
				})
			},
			xubaoFn() {
				httpRequest.request('/api/user/xbUserGb', 'GET', {
					id: this.currentid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.init()
					}
				})
			},
			tingbaoFn() {
				httpRequest.request('/api/user/stopUserGb', 'GET', {
					id: this.currentid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.init()
					}
				})
			},
			modalcancel() {
				this.modal.modalShow = false
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/user/userGbIndex1', 'GET', {
					page: page || 1,
					limit: _this.limit,
					status: this.tabsid,
					keyword: this.keywords,
					company_id:this.company_id
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			changetab(e) {
				this.tabsid = e.value
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>